package frist50;

import org.junit.jupiter.api.Test;

public class T0013 {
    public int romanToInt(String s) {
        int sum = 0;
        for (int i = 0; i < s.length() - 1; i++) {
            int a = getNum(s.charAt(i));
            int b = getNum(s.charAt(i + 1));
            sum +=a<b?a*(-1):a;
        }
        sum+=getNum(s.charAt(s.length()-1));
        return sum;
    }

    public int getNum(char c) {
        String[] strings = {"M", "D", "C", "L", "X", "V", "I"};
        int[] ints = {1000, 500, 100, 50, 10, 5, 1};
        for (int i = 0; i < strings.length; i++) {
            if (strings[i].equals(String.valueOf(c))) {
                return ints[i];
            }
        }
        return 0;
    }
    @Test
    public void test() {


        System.out.println(romanToInt("III"));

    }
}
